package com.kindnesslibrary.network.post;

import android.os.Handler;

import com.kindnesslibrary.network.HttpConfig;
import com.kindnesslibrary.network.HttpUtils;
import com.kindnesslibrary.network.callback.HttpCallBack;

/**
 * Post提交线程
 */
public class PostFormThread extends PostCallBack {

    private HttpCallBack httpCallBack;

    private HttpUtils httpUtils = HttpUtils.getInstance();

    public PostFormThread(String url, Object content, Handler handler, HttpCallBack httpCallBack) {
        super(url, content, handler);
        this.httpCallBack = httpCallBack;
    }

    @Override
    public void runing() {
        post();
    }

    /**
     * post请求数据
     */
    void post(){
        if(httpCallBack != null){
            String result = httpUtils.post(getUrl(), getContent());
            httpCallBack.onRequestOk(result);
        }else{
            sendMessage(HttpConfig.MSG_CANCEL, 0, null);
        }
    }

}
